$(function() {
    window.readerObj = {
        chaptersInfo: {},
        chapters: [],
        chapterNum: 0,
        chapterMap: {},
        fetchCid: null,
        setChapterInfo: function(t) {
            this.chaptersInfo = JSON.parse(JSON.stringify(t))
        },
        getInfoByCid: function(t) {
            return this.chapterMap[t]
        },
        setChapters: function(t) {
            this.chapters = t,
            this.chapterNum = t.length;
            var e = this.chapterMap;
            t.forEach(function(t, i) {
                var a = t.chapterId;
                t = JSON.parse(JSON.stringify(t)),
                t._index = i + 1;
                var n = e[a] || {};
                t._text = n._text || null,
                t._textType = n._textType || null,
                e[a] = t
            }),
            e = null
        },
        setRenChapter: function(t) {
            return t = +t,
            this.chapterMap[t] || (t = +this.chapters[0].chapterId),
            this.fetchCid = t,
            t
        },
        getCurCont: function(t) {
            var e = this.fetchCid;
            if (!e)
                throw new Error("未使用 setRenChapter 设置当前ID");
            this._getContByCid(e, function(e, i) {
                t(e, i)
            })
        },
        getPrevCont: function(t, e) {
            var i = this.chapterMap[t]._index - 1;
            i = this.chapters[i - 1],
            i && (i = i.chapterId),
            this._getContByCid(i, function(t, i) {
                e(t, i)
            })
        },
        getNextCont: function(t, e) {
            var i = this.chapterMap[t]._index - 1;
            i = this.chapters[i + 1],
            i && (i = i.chapterId),
            this._getContByCid(i, function(t, i) {
                e(t, i)
            })
        },
        preload: function(t, e) {},
        _getContByCid: function(t, e) {
            function i(t) {
                var i = n._index;
                1 == i ? r.isFirst = !0 : i == a.chapterNum && (r.isEnd = !0),
                r.data = {
                    cid: n.chapterId,
                    cname: n.chapterName,
                    index: i,
                    updatetime: n.chapterUpdateTime,
                    wordCount: n.wordCount,
                    price: n.chapterPrice,
                    oriPrice: n.oriPrice,
                    payStatus: n.payStatus
                },
                e(t, r)
            }
            var a = this
              , n = this.chapterMap[t];
            if (!n)
                return e("", {
                    state: 5
                });
            var r = {
                state: 1,
                type: 1,
                isFirst: !1,
                isEnd: !1,
                chapterNum: this.chapterNum,
                data: {}
            }
              , c = n._text
              , o = !1;
            c && (1 == n._textType ? o = !0 : 2 != n._textType || n.isFreeRead || n.isBuy || (o = !0));
            var s = this.getCookie("usertoken");
            if (o)
                r.type = n._textType,
                i(c);
            else {
                var d;
                n.isFreeRead ? d = this.chaptersInfo.freeContUrlPrefix + n.contUrlSuffix : n.isBuy ? d = this.chaptersInfo.chargeContUrlPrefix + n.contUrlSuffix + "&userToken=" + s : (r.type = 2,
                d = this.chaptersInfo.shortContUrlPrefix + n.shortContUrlSuffix),
                this._fetch(d, function(t, e) {
                    e && (r.state = {
                        1: 2,
                        2: 3,
                        3: 4
                    }[e]),
                    i(t)
                })
            }
        },
        getCookie: function(t) {
            var e, i = new RegExp("(^| )" + t + "=([^;]*)(;|$)");
            return (e = document.cookie.match(i)) ? unescape(e[2]) : null
        },
        _fetch: function(t, e) {
            if (!t)
                return e("", 2);
            var i = this;
            $.ajax({
                url: t,
                success: function(t) {
                    if (200 != t.state)
                        return e("", 2);
                    var a = t.ChapterContent.trim() || "";
                    if (!a)
                        return e("", 3);
                    try {
                        a = i._decodeCont(t.ChapterContent) || ""
                        window.decodeCont = i._decodeCont
                    } catch (t) {}
                    if (!a)
                        return e("", 2);
                    e(a, 0)
                },
                error: function() {
                    e("", 1)
                }
            })
        },
        _decodeCont: function(t) {
            return t = function(t) {
                return t.split("").map(function(t) {
                    var e, i;
                    return t.match(/[A-Za-z]/) ? (e = Math.floor(t.charCodeAt(0) / 97),
                    i = (t.toLowerCase().charCodeAt(0) - 83) % 26 || 26,
                    String.fromCharCode(i + (0 == e ? 64 : 96))) : t
                }).join("")
            }(t),
            function(t) {
                var e, i, a, n, r, c, o, s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", d = "", l = 0;
                for (t = t.replace(/[^A-Za-z0-9\+\/\=]/g, ""); l < t.length; )
                    n = s.indexOf(t.charAt(l++)),
                    r = s.indexOf(t.charAt(l++)),
                    c = s.indexOf(t.charAt(l++)),
                    o = s.indexOf(t.charAt(l++)),
                    e = n << 2 | r >> 4,
                    i = (15 & r) << 4 | c >> 2,
                    a = (3 & c) << 6 | o,
                    d += String.fromCharCode(e),
                    64 != c && (d += String.fromCharCode(i)),
                    64 != o && (d += String.fromCharCode(a));
                return function(t) {
                    for (var e, i = "", a = 0, n = 0, r = 0; a < t.length; )
                        n = t.charCodeAt(a),
                        n < 128 ? (i += String.fromCharCode(n),
                        a++) : n > 191 && n < 224 ? (r = t.charCodeAt(a + 1),
                        i += String.fromCharCode((31 & n) << 6 | 63 & r),
                        a += 2) : (r = t.charCodeAt(a + 1),
                        e = t.charCodeAt(a + 2),
                        i += String.fromCharCode((15 & n) << 12 | (63 & r) << 6 | 63 & e),
                        a += 3);
                    return i
                }(d)
            }(t)
        }
    }
}),
$(function() {
    function t(t) {
        readerObj.setRenChapter(t || ""),
        readerObj.getCurCont(function(t, e) {
            h.find(".js-chapContainer").remove();
            var i = o(t, e);
            h.append(i),
            e = JSON.parse(JSON.stringify(e)),
            e.$el = i,
            b = [e],
            a(),
            $(window).scroll(a);
            var r = ~~(.33333 * window.innerHeight);
            u = e.data.cid,
            n(u),
            c(e),
            $(window).scroll(function() {
                var t, e, i;
                if (b.some(function(a, n) {
                    var c = a.$el
                      , o = c[0].getBoundingClientRect();
                    if (o.top < r && o.bottom > r)
                        return t = a.data.cid,
                        e = a,
                        i = n,
                        !0
                }),
                t && u != t && (u = t,
                n(u),
                c(e),
                !(b.length < 4))) {
                    var a = i - 3
                      , o = i + 3
                      , s = [];
                    if (o <= b.length - 1 && (s = b.splice(o, b.length - o),
                    s.forEach(function(t) {
                        t.$el.remove()
                    })),
                    a >= 0) {
                        s = b.splice(0, a + 1);
                        var d = Math.max(0, window.scrollY + (s[0].$el[0].getBoundingClientRect().top - b[0].$el[0].getBoundingClientRect().top));
                        s.forEach(function(t) {
                            t.$el.remove()
                        }),
                        window.scrollTo(0, d)
                    }
                }
            })
        }),
        $.get(appConfig.xhrUrl.ticket + "/sapi/monthticket/setting", function(t) {
            200 === t.status && (t = t.data.recSendConfList,
            window.localStorage.setItem("__read_chapters_limit", t.recRead.recReadChapter))
        }, "json")
    }
    function e(t) {
        var e = b[0];
        if (e.isFirst)
            return t();
        readerObj.getPrevCont(e.data.cid, function(e, i) {
            if (5 == i.state)
                return t();
            var a = window.scrollY
              , n = o(e, i);
            h.prepend(n);
            var r = n[0].scrollHeight + 20;
            window.scrollTo(0, a + r),
            i = JSON.parse(JSON.stringify(i)),
            i.$el = n,
            b.unshift(i),
            t()
        })
    }
    function i(t) {
        var e = b[b.length - 1];
        if (e.isEnd)
            return t();
        readerObj.getNextCont(e.data.cid, function(e, i) {
            if (5 == i.state)
                return t();
            var a = o(e, i);
            h.append(a),
            i = JSON.parse(JSON.stringify(i)),
            i.$el = a,
            b.push(i),
            t()
        })
    }
    function a() {
        function t() {
            --c || (a.running = !1)
        }
        if (!a.running) {
            a.running = !0;
            var n = window.scrollY
              , r = document.body.scrollHeight - window.innerHeight - n
              , c = 1;
            n < 30 && (c++,
            e(t)),
            r < 30 && (c++,
            i(t)),
            t()
        }
    }
    function n(t) {
        var e = s.bookId
          , i = readerObj.getInfoByCid(t)
          , a = readerObj.chapterNum
          , n = i._index
          , c = Math.max(1, ~~(n / a * 100));
        $.bookShelf.update(e, {
            cid: t,
            cname: i.chapterName,
            percent: c
        }),
        $.log.click("read", "tochapter", "show", {
            bid: e,
            chapterid: t,
            freeread: +!!i.isFreeRead
        }),
        r(e, t),
        window.history.replaceState("", {}, "/reader?bid=" + e + "&cid=" + t)
    }
    function r(t, e) {
        $.get("/api/gettime", function(i) {
            i = +i;
            var a, n = appConfig._.userId, r = !!n, c = n ? "user_" + n : "user_unknow";
            try {
                a = JSON.parse(window.localStorage.getItem("__read_chapters"))
            } catch (t) {}
            a || (a = {}),
            a[c] || (a[c] = {
                chapters: {},
                updatetime: i,
                length: 0,
                fired: !1
            });
            var o = a[c]
              , s = $.util
              , d = "yyyy-MM-dd";
            if (s.dateFormat(o.updatetime, d) != s.dateFormat(i, d) && (o.updatetime = i,
            o.length = 0,
            o.fired = !1),
            !o.fired) {
                var l = window.localStorage.getItem("__read_chapters_limit");
                if (l = +l || 50,
                o.updatetime = i,
                r) {
                    var p = a.user_unknow;
                    if (p && p.length && s.dateFormat(p.updatetime, d) == s.dateFormat(i, d)) {
                        for (var f in p.chapters)
                            o.chapters[f] = 1;
                        o.length = p.length + o.length,
                        p.length = 0,
                        p.chapters = {}
                    }
                }
                var u = t + "-" + e;
                o.chapters[u] || (o.chapters[u] = 1,
                o.length = o.length + 1);
                var h = appConfig.imei;
                r && o.length >= l && ($.post(appConfig.xhrUrl.ticket + "/pcapi/vote/issuerecommendticket", {
                    userId: n,
                    readChapters: 1,
                    platform: "an",
                    timestamp: "1234567890",
                    key: "appapi",
                    imei: h,
                    sn: h,
                    sign: $.md5("imei=" + h + "&platform=an&readChapters=1&sn=" + h + "&timestamp=1234567890&userId=" + n + "&skey=8771731b23164da09a5b80c4d7e4c619").toUpperCase()
                }),
                o.fired = !0),
                window.localStorage.setItem("__read_chapters", JSON.stringify(a))
            }
        }, "text")
    }
    function c(t) {
        var e = t.data.cname
          , i = +t.chapterNum
          , a = +t.data.index
          , n = Math.max(1, ~~(a / i * 100)) + "%";
        g.text(e),
        m.text("阅读到 " + n)
    }
    function o(t, e) {
        function i(t) {
            return t = '<div class="chapter-content">' + t + "</div>",
            e.isEnd && (t += '<div class="chapter-end-notice">已经到了最后一章，没有更多了哦~</div>'),
            e.isFirst,
            '<div class="chapter-container js-chapContainer">' + t + '<span class="publish-time">\t\t\t\t本章发布于' + $.util.dateFormat(r.updatetime, "yyyy-MM-dd hh:ss") + "</span></div>"
        }
        var a = e.state
          , r = e.data || {};
        if (t = '<p class="chapter-p">' + t.trim().split(/\<br\s*\/\>/g).map(function(t) {
            return t.trim()
        }).join('</p><p class="chapter-p">') + "</p>",
        r.cname && (t = '<h3 class="chapter-title">' + r.cname + "</h3>" + t),
        1 == a) {
            var c = e.type;
            if (1 == c)
                return $($(i(t)));
            if (2 == c) {
                var o = "";
                if (void 0 !== l.sdou)
                    if ((o = +l.sdou) < r.price) {
                        var d = $.log.attr("read-tochapter-recharge", {
                            bid: s.bookId,
                            chapterid: r.cid
                        });
                        o = '<p class="chapter-nv-account">账户余额：' + o + '书豆，余额不足，请<a href="/recharge" target="_blank" data-clog="' + d + '">充值后购买</a></p>'
                    } else
                        o = '<p class="chapter-nv-account">账户余额：' + o + "书豆</p>";
                return t += '<i></i><div class="chapter-needpay-view">\t\t\t\t\t<i class="chapter-nv-line"></i>\t\t\t\t\t<div class="chapter-nv-title">\t\t\t\t\t\t<span>订购本章</span>\t\t\t\t\t</div>\t\t\t\t\t<p class="chapter-nv-desc">本章为付费章节，感谢你对网络文学的正版发展大力支持，同时感谢你对作者的支持</p>\t\t\t\t\t<p class="chapter-nv-info">\t\t\t\t\t\t计费方式：<span>1000字/' + s.price + "豆</span>&nbsp;&nbsp;本章字数：<span>" + r.wordCount + '字</span>\t\t\t\t\t</p>\t\t\t\t\t<div class="chapter-nv-btn js-toBuy">订购本章<i>（' + r.price + "书豆）</i></div>\t\t\t\t\t" + o + "\t\t\t\t</div>",
                function(t) {
                    var e = $($(t));
                    return e.find(".js-toBuy").click(function() {
                        var t = s.bookId
                          , e = r.cid
                          , i = appConfig._.userId;
                        if (n(e),
                        !i)
                            return k.click();
                        $.log.click("read", "tochapter", "buy", {
                            bid: t,
                            chapterid: e
                        });
                        var a = appConfig.imei;
                        $.post("/api/buychapter", {
                            bookId: t,
                            chapterId: e,
                            price: r.price,
                            imei: a
                        }, function(t) {
                            var e = t.state || t.status;
                            if (-1 == e)
                                k.click();
                            else if (200 == e)
                                $.alert("购买成功", function() {
                                    location.reload()
                                });
                            else
                                switch (e) {
                                case 401:
                                case 402:
                                case 403:
                                case 404:
                                case 405:
                                case 406:
                                case 407:
                                case 413:
                                case 432:
                                case 473:
                                    $.alert(t.message, function() {
                                        location.reload()
                                    });
                                    break;
                                default:
                                    $.alert(t.message)
                                }
                        })
                    }),
                    e
                }(i(t))
            }
        } else {
            if (2 == a)
                return t += '<div class="chapter-error-view">\t\t\t\t网络异常，请<span class="chapter-ev-light js-errorBtn">点击这里</span>尝试刷新\t\t\t</div>',
                function(t) {
                    var i = $($(t));
                    return i.find(".js-errorBtn").click(function() {
                        n(e.data.cid),
                        window.location.reload()
                    }),
                    i
                }(i(t));
            if (3 == a)
                return t += '<div class="chapter-error-view">\t\t\t\t文本解析异常，<span class="chapter-ev-light js-errorBtn">点击这里</span>上报给客服，感谢您的反馈\t\t\t</div>',
                function(t) {
                    var i = $($(t));
                    return i.find(".js-errorBtn").click(function() {
                        n(e.data.cid),
                        $.util.link("/")
                    }),
                    i
                }(i(t));
            if (4 == a)
                return t += '<div class="chapter-error-view">\t\t\t\t本章内容缺失，<span class="chapter-ev-light js-errorBtn">点击这里</span>上报给客服，感谢您的反馈\t\t\t</div>',
                function(t) {
                    var i = $($(t));
                    return i.find(".js-errorBtn").click(function() {
                        n(e.data.cid),
                        $.util.link("/")
                    }),
                    i
                }(i(t))
        }
    }
    var s = JSON.parse($(".js-dataBookInfo").text())
      , d = JSON.parse($(".js-dataChapters").text())
      , l = JSON.parse($(".js-dataUserInfo").text())
      , p = $.util.parseSearch()
      , f = [];
    if (d.chapterList.forEach(function(t) {
        f = f.concat(t.volumeList)
    }),
    delete d.chapterList,
    readerObj.setChapterInfo(d),
    readerObj.setChapters(f),
    !readerObj.chapterNum || !readerObj.chapters.length) {
        $(".reader-operates-view").hide(),
        $(".js-readerView").find(".js-chapContainer").remove();
        return void $(".js-readerView").append('<div class="chapter-container js-chapContainer"><div class="chapter-content"><div class="chapter-error-view">本书尚无内容，还请等待作者更新。</div></div></div>')
    }
    var u, h = $(".js-readerView"), v = $(".js-chapterTop"), g = v.find(".js-title"), m = v.find(".js-progress"), C = function() {
        function t() {
            e.hide()
        }
        var e = $(".js-catalView")
          , i = $(".js-catalWindow")
          , a = e.find(".js-list")
          , r = e.find(".js-close")
          , c = "";
        f.forEach(function(t) {
            var e = t.chapterId;
            c += '<li class="c-' + e + '" data-cid="' + e + '">' + t.chapterName,
            t.isFreeRead || (c += ' <img height="12" src="/assets/chapter/chapter_vip.png" />'),
            t.isBuy && (c += '<img src="/assets/chapter/isbuy.png" />'),
            c += "</li>"
        }),
        a.html(c),
        a.find("li").click(function() {
            var e = $(this)
              , i = this.dataset.cid;
            e.hasClass("active") ? t() : (n(i),
            window.location.reload())
        }),
        r.click(t),
        e.click(t),
        i.click(function(t) {
            t.stopPropagation()
        });
        var o;
        return {
            show: function(t) {
                o && o.removeClass("active"),
                o = a.find(".c-" + t),
                o.addClass("active"),
                e.show();
                var i = o[0].offsetTop
                  , n = a[0].offsetHeight;
                a[0].scrollTo(0, ~~(i - n / 2))
            }
        }
    }(), k = $(".js-webTop").find(".js-operateView").find(".js-login"), b = [];
    p.cid ? t(p.cid) : $.bookShelf.getOne(p.bid, function(e) {
        t(e ? e.chapterid : "")
    }),
    $(".js-readerOpers").on("click", "li", function() {
        var t = this.dataset.act;
        $(this).clog(),
        "login" == t ? k.click() : "cover" == t ? $.util.link("/cover?bid=" + s.bookId, "_self") : "catal" == t ? C.show(u) : "recticket" == t ? $(".js-subRecTicket").click() : "monticket" == t ? $(".js-subMonthTicket").click() : "present" == t && $(".js-subPresent").click()
    })
}),
window.PAGEDATA = JSON.parse($(".js-dataBookInfo").text()),
$(function() {
    function t() {
        a.hide()
    }
    if (PAGEDATA) {
        var e = $(".js-subMonthTicket");
        if (e[0]) {
            var i, a = $(".js-monthTicketPrompt"), n = a.find(".js-fixProView"), r = a.find(".js-closeBtn"), c = a.find(".js-submitBtn"), o = a.find(".js-option"), s = PAGEDATA.monthTicket, d = +s.ticketBalance;
            d ? function() {
                var t = {};
                s.voteList.forEach(function(e) {
                    t[e.voteId] = 9999 == e.voteId ? 1 : +e.num
                }),
                o.each(function(e, a) {
                    $(a).click(function() {
                        o.each(function(t, e) {
                            $(e).removeClass("selected")
                        }),
                        $(this).addClass("selected"),
                        i = this.dataset.vid,
                        d && d >= t[i] ? c.removeClass("disable") : c.addClass("disable")
                    })
                }),
                c.click(function() {
                    $(this).clog(),
                    !d || d < t[i] || $.post("/api/sendMonthTicket", {
                        bookId: PAGEDATA.bookId,
                        voteId: i,
                        imei: appConfig.imei,
                        sn: appConfig.imei
                    }, function(t) {
                        200 == t.status ? ($.log.click("gratuity", "month", "success", {
                            bid: PAGEDATA.bookId
                        }),
                        $.alert("投票成功", function() {
                            location.reload()
                        })) : $.alert(t.message)
                    })
                })
            }() : function() {
                var t = a.find(".js-gold");
                $.get("/api/getuserinfo", {
                    imei: appConfig.imei
                }).done(function(e) {
                    if (200 == e.status) {
                        var i = s.rewardInfo[0]
                          , a = +i.giftPrice
                          , n = +e.data.sdou;
                        t.html(n + "书豆"),
                        c.click(function() {
                            n < a ? (r.click(),
                            $.prompt("您的书豆不足" + a + "，请先进行充值", "书豆余额不足", function() {
                                $.util.link("/recharge", !0),
                                $.prompt("您是否充值完毕？", function() {
                                    location.reload()
                                }, {
                                    sureText: "充值完毕",
                                    cancelText: "放弃充值"
                                })
                            }, {
                                sureText: "去充值",
                                cancelText: "取消"
                            })) : $.ajax({
                                url: appConfig.xhrUrl.ticket + "/sapi/reward/buy",
                                type: "POST",
                                data: {
                                    _platform: 1,
                                    userId: appConfig._.userId,
                                    bookId: PAGEDATA.bookId,
                                    giftId: i.giftId,
                                    giftPrice: a,
                                    imei: appConfig.imei,
                                    sn: appConfig.imei,
                                    platform: "an"
                                },
                                dataType: "json"
                            }).then(function(t) {
                                200 == t.status ? ($.log.click("gratuity", "month", "subygift", {
                                    bid: PAGEDATA.bookId
                                }),
                                $.alert("打赏并投递成功", function() {
                                    location.reload()
                                })) : $.alert(t.message)
                            })
                        })
                    }
                })
            }(),
            e.click(function() {
                return $(this).clog(),
                appConfig._.userId ? PAGEDATA.isAuthor ? void $.alert("您是本书作者，不能参与投票") : (o[0].click(),
                void a.show()) : void $.util.openLogin()
            }),
            a.click(t),
            r.click(t),
            n.click(function(t) {
                t.stopPropagation()
            })
        }
    }
}),
$(function() {
    function t() {
        c.hide()
    }
    if (PAGEDATA) {
        var e = $(".js-subRecTicket");
        if (e[0]) {
            var i = PAGEDATA.recTicket
              , a = +i.ticketBalance
              , n = {};
            i.voteList.forEach(function(t) {
                n[t.voteId] = 9999 == t.voteId ? 1 : +t.num
            });
            var r, c = $(".js-recTicketPrompt"), o = c.find(".js-fixProView"), s = c.find(".js-closeBtn"), d = c.find(".js-submitBtn"), l = c.find(".js-option");
            l.each(function(t, e) {
                $(e).click(function() {
                    l.each(function(t, e) {
                        $(e).removeClass("selected")
                    }),
                    $(this).addClass("selected"),
                    r = this.dataset.vid,
                    a && a >= n[r] ? d.removeClass("disable") : d.addClass("disable")
                })
            }),
            d.click(function() {
                $(this).clog(),
                !a || a < n[r] || $.post("/api/sendRecTicket", {
                    bookId: PAGEDATA.bookId,
                    voteId: r,
                    imei: appConfig.imei,
                    sn: appConfig.imei
                }, function(t) {
                    200 == t.status ? ($.log.click("gratuity", "recommend", "success", {
                        bid: PAGEDATA.bookId
                    }),
                    $.alert("投票成功", function() {
                        location.reload()
                    })) : $.alert(t.message)
                })
            }),
            e.click(function() {
                return $(this).clog(),
                appConfig._.userId ? PAGEDATA.isAuthor ? void $.alert("您是本书作者，不能参与投票") : (l[0].click(),
                void c.show()) : void $.util.openLogin()
            }),
            c.click(t),
            s.click(t),
            o.click(function(t) {
                t.stopPropagation()
            })
        }
    }
}),
$(function() {
    function t() {
        function t(t) {
            function e(t) {
                $(this).clog(),
                n(this)
            }
            function n(t) {
                w && w.removeClass("active"),
                t = $(t),
                t.addClass("active"),
                w = t;
                var e = t.data("gift")
                  , i = +e.price;
                h.text(i),
                o.sdou < i ? (m.show(),
                u.addClass("disable")) : (m.hide(),
                u.removeClass("disable"))
            }
            t = JSON.parse(JSON.stringify(t));
            var r = t.gifts.list
              , c = r.length
              , s = t.reward
              , d = [];
            r = r.map(function(t) {
                return $('<div class="option">\t\t\t\t\t<div class="icon"><img src="' + t.icon + '" /></div>\t\t\t\t\t<p class="name">' + t.title + '</p>\t\t\t\t\t<p class="gold"><i>' + t.price + '</i>书豆</p>\t\t\t\t\t<p class="fans">' + t.fansValue + "粉丝值</p>\t\t\t\t</div>").data("gift", {
                    id: t.id,
                    price: t.price
                }).click(e)
            });
            for (var l = 0; l < c; l += 8)
                d.push(r.slice(l, l + 8));
            n(r[0]),
            i(d),
            setTimeout(a, 1, s)
        }
        l.html(""),
        C.html("").hide(),
        m.hide(),
        p.html("").hide(),
        j && clearInterval(j),
        g.text(o.sdou),
        l.html('<div class="loading">礼物正在飞奔而来，请稍等...</div>'),
        e(function(e) {
            200 == e.status && t(e.data)
        })
    }
    function e(t, e) {
        $.ajax({
            url: appConfig.xhrUrl.ticket + "/sapi/reward/info",
            type: "POST",
            data: {
                updatetime: 0,
                _platform: 1,
                userId: b,
                bookId: PAGEDATA.bookId
            },
            dataType: "json",
            success: t,
            error: e
        })
    }
    function i(t) {
        function e(e, a, r) {
            var c = t[e];
            c = i(c, a),
            l.append(c),
            "prev" == a ? n.animate({
                left: "100%"
            }, "linear") : "next" == a && n.animate({
                left: "-100%"
            }, "linear"),
            c.animate({
                left: 0
            }, "linear", r),
            n = c
        }
        function i(t, e) {
            var i;
            switch (e) {
            case "prev":
                i = "-100%";
                break;
            case "cur":
                i = 0;
                break;
            case "next":
                i = "100%"
            }
            return t.css("left", i)
        }
        var a = t.length
          , n = null;
        t = t.map(function(t, e) {
            var i = $('<div class="clear"></div>');
            return t.forEach(function(t, i) {
                t[0].dataset.clog = $.log.attr(i + 1, {
                    bid: PAGEDATA.bookId,
                    pagearea: e + 1
                })
            }),
            i.append(t),
            i
        }),
        l.html(""),
        n = i(t[0], "cur"),
        l.append(n),
        a > 1 && function() {
            function t(t) {
                r.forEach(function(t) {
                    t.removeClass("active disable")
                }),
                r[t].addClass("active"),
                1 == t ? r[0].addClass("disable") : t == a && r[r.length - 1].addClass("disable")
            }
            var i = 1
              , n = !1
              , r = []
              , c = $('<i class="btn prev"></i>')
              , o = $('<i class="btn next"></i>');
            r.push(c);
            for (var s = 0; s < a; s++)
                r.push($('<i class="dot"></i>'));
            r.push(o),
            t(i),
            c.click(function() {
                1 != i && (n || (n = !0,
                i--,
                e(i - 1, "prev", function() {
                    n = !1
                }),
                t(i)))
            }),
            o.click(function() {
                i != a && (n || (n = !0,
                i++,
                e(i - 1, "next", function() {
                    n = !1
                }),
                t(i)))
            }),
            p.html("").show().append(r)
        }()
    }
    function a(t) {
        if (t && t.length) {
            var e = 0
              , i = t.length;
            t = t.map(function(t) {
                return $("<p>" + t.nickname + " " + t.title + "</p>")
            });
            var a = t[e];
            C.append(a),
            C.show(),
            i < 2 || (j = setInterval(function() {
                e = e == i - 1 ? 0 : e + 1;
                var n = t[e].css("top", 16);
                C.append(n),
                a.animate({
                    top: -16
                }, "linear", function() {
                    a.remove(),
                    a = n
                }),
                n.animate({
                    top: 0
                }, "linear")
            }, 2e3))
        }
    }
    function n() {
        return b ? PAGEDATA.isAuthor ? void $.alert("您是本书作者，不能参与打赏") : void $.get("/api/getuserinfo", {
            imei: appConfig.imei
        }).done(function(e) {
            200 == e.status ? (o = e.data,
            t(),
            s.show()) : $.util.logout(function() {
                $.util.openLogin()
            })
        }) : ($.util.openLogin(),
        void $.log.click("gratuity", "present", "login", {
            bid: PAGEDATA.bookId
        }))
    }
    function r() {
        j && clearInterval(j),
        s.hide()
    }
    if (PAGEDATA) {
        var c = $(".js-subPresent");
        if (c[0]) {
            var o, s = $(".js-presentPrompt"), d = s.find(".js-fixProView"), l = s.find(".js-optionsView"), p = s.find(".js-selectMore"), f = s.find(".js-closeBtn"), u = s.find(".js-submitBtn"), h = s.find(".js-submitGold"), v = s.find(".js-toRecharge"), g = s.find(".js-hadGold"), m = s.find(".js-errorNotice"), C = s.find(".js-history"), k = s.find(".js-commentText"), b = appConfig._.userId, w = (new Date,
            null), j = null;
            v.click(function() {
                $(this).clog(),
                $.util.link("/recharge", !0)
            }),
            u.click(function() {
                if (w && o) {
                    var t = w.data("gift");
                    if (!(+o.sdou < +t.price)) {
                        var e = k.val().trim() || "";
                        $.post("/api/sendPresent", {
                            userId: b,
                            bookId: PAGEDATA.bookId,
                            giftId: t.id,
                            giftPrice: t.price,
                            imei: appConfig.imei,
                            sn: appConfig.imei,
                            comment: e
                        }, function(t) {
                            200 == t.status ? (e ? $.log.click("gratuity", "present", "suwithcom", {
                                bid: PAGEDATA.bookId
                            }) : $.log.click("gratuity", "present", "success", {
                                bid: PAGEDATA.bookId
                            }),
                            $.alert("打赏成功", function() {
                                n()
                            })) : $.alert(t.message)
                        })
                    }
                }
            }),
            c.click(function() {
                $(this).clog(),
                n()
            }),
            s.click(r),
            f.click(r),
            d.click(function(t) {
                t.stopPropagation()
            })
        }
    }
});
